package com.goodving.guli.bt.weight.family;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.activity.MemberInfoBaseActivity;
import com.goodving.guli.activity.MemberInfoSetNameActivity;
import com.goodving.guli.activity.PersonInfoActivity;
import com.goodving.guli.activity.SystemBarTintActivity;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.ui.WeightUserAvatar;
import com.goodving.guli.bt.weight.UserInfo;
import com.goodving.guli.bt.weight.UserInfoManager;
import com.goodving.guli.view.C3247b;

import java.util.ArrayList;
import java.util.List;

public class WeightFamilyMemberActivity extends SystemBarTintActivity implements OnClickListener {
    private static final String f11460b = "WeightFamilyMemberActivity";
    private Context f11461a;
    private ListView f11462c;
    private C2029n f11463d;
    private List<UserInfo> f11464e;
    private ImageView f11465f;

    public WeightFamilyMemberActivity() {
        this.f11461a = this;
        this.f11464e = new ArrayList();
    }

    private void m15853a() {
        this.f11462c = (ListView) findViewById(R.id.family_members_dymantic_list);
        this.f11465f = (ImageView) findViewById(R.id.add_member_plus);
        this.f11465f.setOnClickListener(this);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.add_member_plus:
                if (!Utils.m8084k(this.f11461a)) {
                    C3247b.m22930a(this.f11461a, getString(R.string.please_connect_internet), 0).show();
                } else if (UserInfoManager.getInstance().m15595c() >= 16) {
                    C3247b.m22930a(this.f11461a, getString(R.string.over_the_max_user_count), 0).show();
                } else {
                    this.f11461a.startActivity(new Intent(this.f11461a, MemberInfoSetNameActivity.class));
                    C0668a.m8128a(this.f11461a, C0668a.fl, C0668a.fm);
                }
                break;
            default:
                break;
        }
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_family_member);
        m15853a();
    }

    protected void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.aL);
        C0668a.m8138b((Activity) this);
    }

    protected void onResume() {
        super.onResume();
        this.f11464e = UserInfoManager.getInstance().m15601e();
        this.f11463d = new C2029n(this);
        this.f11462c.setAdapter(this.f11463d);
        this.f11462c.setOnItemClickListener(new C2028m(this));
        C0668a.m8133a(C0668a.aL);
        C0668a.m8124a((Activity) this);
    }

    class C2030o {
        WeightUserAvatar f11505a;
        TextView f11506b;
        TextView f11507c;
        final /* synthetic */ C2029n f11508d;

        C2030o(C2029n c2029n) {
            this.f11508d = c2029n;
        }
    }

    class C2029n extends BaseAdapter {
        final /* synthetic */ WeightFamilyMemberActivity f11504a;

        public C2029n(WeightFamilyMemberActivity weightFamilyMemberActivity) {
            this.f11504a = weightFamilyMemberActivity;
        }

        public int getCount() {
            return this.f11504a.f11464e.size();
        }

        public Object getItem(int i) {
            return this.f11504a.f11464e.get(i);
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            C2030o c2030o;
            GuliLog.tracePrintInfo("WeightFamilyMemberActivity", "adapter getView()");
            if (view == null) {
                view = LayoutInflater.from(this.f11504a.f11461a).inflate(R.layout.family_member_item, null);
                C2030o c2030o2 = new C2030o(this);
                c2030o2.f11505a = (WeightUserAvatar) view.findViewById(R.id.member_icon);
                c2030o2.f11506b = (TextView) view.findViewById(R.id.member_name);
                c2030o2.f11507c = (TextView) view.findViewById(R.id.member_content);
                view.setTag(c2030o2);
                c2030o = c2030o2;
            } else {
                c2030o = (C2030o) view.getTag();
            }
            UserInfo userInfo = (UserInfo) this.f11504a.f11464e.get(i);
            c2030o.f11505a.m15375a(userInfo.name);
            c2030o.f11505a.m15374a(Utils.m8048c(((UserInfo) this.f11504a.f11464e.get(i)).uid));
            Utils.m8008a(userInfo, c2030o.f11505a);
            if (!(userInfo.name == null || userInfo.name.isEmpty())) {
                c2030o.f11506b.setText(userInfo.name);
            }
            return view;
        }
    }

    class C2028m implements AdapterView.OnItemClickListener {
        final /* synthetic */ WeightFamilyMemberActivity f11503a;

        C2028m(WeightFamilyMemberActivity weightFamilyMemberActivity) {
            this.f11503a = weightFamilyMemberActivity;
        }

        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            UserInfo userInfo = (UserInfo) this.f11503a.f11464e.get(i);
            if (userInfo == null || userInfo.uid != -1) {
                Intent intent = new Intent(this.f11503a.f11461a, UserInfoActivity.class);
                intent.putExtra(MemberInfoBaseActivity.USER_INFO_UID, ((UserInfo) this.f11503a.f11464e.get(i)).uid);
                this.f11503a.f11461a.startActivity(intent);
                C0668a.m8126a(this.f11503a.f11461a, C0668a.gf);
                return;
            }
            Intent intent2 = new Intent();
            intent2.setClass(this.f11503a.f11461a, PersonInfoActivity.class);
            this.f11503a.startActivity(intent2);
        }
    }


}
